package org.sofun;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sofun.subscription.example.BugFixDemo;
import org.sofun.subscription.example.LoggingExample;
import org.sofun.subscription.example.QuarterlyTestDemo;
import org.sofun.subscription.example.SubscriptionServiceExample;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Main {

    private static final Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) {
        logger.info("启动申购开放日生成系统...");

        // 启动Spring Boot应用
        ApplicationContext context = SpringApplication.run(Main.class, args);



        // 运行季度测试演示
        QuarterlyTestDemo quarterlyTestDemo = context.getBean(QuarterlyTestDemo.class);
        quarterlyTestDemo.demonstrateQuarterlyOpenDays();
        quarterlyTestDemo.demonstrateDifferentQuarterlyRules();
        quarterlyTestDemo.demonstrateExpirationFiltering();

        // 运行Bug修复演示
        BugFixDemo bugFixDemo = context.getBean(BugFixDemo.class);
        bugFixDemo.demonstrateBugFix();
        bugFixDemo.demonstrateDifferentRules();

        // 运行日志示例
        LoggingExample loggingExample = context.getBean(LoggingExample.class);
        loggingExample.runAllExamples();

        // 运行业务示例
        SubscriptionServiceExample example = context.getBean(SubscriptionServiceExample.class);
        example.runAllExamples();

        logger.info("系统启动完成！");
        logger.info("REST API 可通过以下地址访问:");
        logger.info("=== 申购开放日生成服务 ===");
        logger.info("- 健康检查: GET http://localhost:8080/api/subscription/health");
        logger.info("- 生成开放日: POST http://localhost:8080/api/subscription/open-days");
        logger.info("- 计算募集期间: POST http://localhost:8080/api/subscription/fund-periods");
        logger.info("- 一站式服务: POST http://localhost:8080/api/subscription/complete");
    }
}